package com.controller;

import com.base.BaseController;
import com.base.BasePageReq;
import com.base.BasePageRes;
import com.req.CollectionReq;
import com.res.CollectionRes;
import com.res.UserRes;
import com.service.CollectionService;
import com.util.common.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/collection")
@RestController
@Api(tags = "收藏")
public class CollectionController extends BaseController {
    @Autowired
    private CollectionService collectionService;
    @PostMapping("/save")
    @ApiOperation("收藏的增删改查")
    public R<CollectionRes> saveCollection(@RequestBody CollectionReq req){
        UserRes user = this.getUser();
        req.setUserId(user.getId());
        return R.ok(collectionService.saveCollection(req));
    }
    @PostMapping("/queryPage")
    @ApiOperation("收藏分页查询")
    public R<BasePageRes> queryPage(@RequestBody BasePageReq pageReq){
        UserRes user = this.getUser();
        pageReq.setUserId(user.getId());
        return R.ok(collectionService.queryPage(pageReq));
    }
}
